package com.congee02.springframework.processor;

import com.congee02.springframework.bean.UserService;
import com.congee02.springframework.beans.BeansException;
import com.congee02.springframework.beans.factory.config.BeanPostProcessor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("userService".equals(beanName)) {
            UserService service = (UserService) bean;
            service.setLocation("上海");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        return bean;
    }
}
